<?php
/**
 *  application.class.php PHPCMS应用程序创建类
 *
 * @copyright			(C) 2005-2010 PHPCMS
 * @license				http://www.phpcms.cn/license/
 * @lastmodify			2010-6-7
 */
class application {
	
	/**
	 * 构造函数
	 */
	public function __construct() {
		$param = pc_base::load_sys_class('param');
		define('ROUTE_M', $param->route_m());
		define('ROUTE_C', $param->route_c());
		define('ROUTE_A', $param->route_a());
		define('CATID', $_GET['catid']);
		define('SELECTID', $this->getNav());
		$this->init();
	}
	
	/**
	 * 调用件事
	 */
	private function init() {
		$controller = $this->load_controller();
		if (method_exists($controller, ROUTE_A)) {
			if (preg_match('/^[_]/i', ROUTE_A)) {
				exit('You are visiting the action is to protect the private action');
			} else {
				call_user_func(array($controller, ROUTE_A));
			}
		} else {
			exit('Action does not exist.');
		}
	}
	
	/**
	 * 加载控制器
	 * @param string $filename
	 * @param string $m
	 * @return obj
	 */
	private function load_controller($filename = '', $m = '') {
		if (empty($filename)) $filename = ROUTE_C;
		if (empty($m)) $m = ROUTE_M;
		$filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php';
		if (file_exists($filepath)) {
			$classname = $filename;
			include $filepath;
			if ($mypath = pc_base::my_path($filepath)) {
				$classname = 'MY_'.$filename;
				include $mypath;
			}
			return new $classname;
		} else {
			exit('Controller does not exist.');
		}
	}
	function getNav(){
		$a_url = array(
		'm=content&c=user&a=company',
		'm=content&c=user&a=designer',
		'm=content&c=lists&a=zhaobiao&catid=20',
		'm=content&c=index&a=lists&catid=14',
		'm=content&c=index&a=lists&catid=45',
		);
	
		$b_url = array('m=content&c=index&a=lists&catid=18',
		'm=content&c=user&a=buy_product',
		'm=content&c=index&a=lists&catid=15',
		'm=content&c=index&a=lists&catid=16',
		);
		$c_url = array(
			'm=content&c=index&a=lists&catid=35',
			'm=content&c=index&a=template_list'
		);
		$d_url = array(
		'm=content&c=lists&a=l_case&catid=24',
		'm=content&c=lists&a=product&catid=18&cid=3411',
		'm=content&c=lists&a=product&catid=18',
		);
		
		$e_url = array('m=content&c=user&a=school',
		'm=content&c=index&a=lists&catid=13',
		'm=content&c=index&a=lists&catid=12',
		'm=content&c=index&a=lists&catid=11',
		'm=content&c=index&a=lists&catid=26',
		'm=content&c=index&a=choose_building_material',
		'm=content&c=index&a=lists&catid=32',
		'm=content&c=index&a=lists&catid=25',
		'm=content&c=index&a=lists&catid=33',
		'm=content&c=index&a=lists&catid=38',
		'm=content&c=index&a=lists&catid=39',
		'm=content&c=index&a=renovation_process',
		);
		
		$url = $_SERVER['QUERY_STRING'];
	//echo $url;exit;
		//index.php?m=content&c=index&a=lists&catid=24
		if(in_array($url, $a_url)){
			$selectid = 1;
		}else if(in_array($url, $b_url)){
			$selectid = 2;
		}
		else if(in_array($url, $c_url)){
			$selectid = 3;
		}else if(in_array($url, $d_url)){
			$selectid = 4;
		}else if(in_array($url, $e_url)){
			$selectid = 5;
		}else {
			$selectid = 1;
		}
		if(ROUTE_C=='index' && ROUTE_A=='init'){
			$selectid = 1;
		}
		return $selectid;
	}
}